
package net.sea.commons.util;

import net.sea.commons.constants.AppConstants;
import net.sea.commons.context.AppContext;

/**
 * 安装信息工具类
 *
 * @author huachengwu 
 */
public class InstallMsgUtils {
	private static AppContext context = AppContext.getInstance();

	/**
	 * 设置安装信息
	 * 
	 * @param msg
	 */
	public static void setInstallMsg(String msg) {
		StringBuffer installMsg = new StringBuffer();
		String lastMsg = (String) context
				.getAttribute(AppConstants.INSTALL_MSG_KEY);
		if (StringUtils.isNotEmpty(lastMsg)) {
			installMsg.append(lastMsg).append(
					System.getProperty("line.separator"));
		}
		if (StringUtils.isNotEmpty(msg)) {
			installMsg.append(msg);
		}
		context.setAttribute(AppConstants.INSTALL_MSG_KEY,
				installMsg.toString());
	}

	/**
	 * 获取安装信息
	 * 
	 * @return 安装信息
	 */
	public static String getInstallMsg() {
		return (String) context.getAttribute(AppConstants.INSTALL_MSG_KEY);
	}

	/**
	 * 设置安装进行信息
	 * 
	 * @param value
	 */
	public static void setInstallProcess(int value) {
		context.setAttribute(AppConstants.PEOCESS_VALUE_KEY, value);
	}

	/**
	 * 获取安装进度
	 * 
	 * @return 安装进度
	 */
	public static int getInstallProcess() {
		int value = (Integer) (context
				.getAttribute(AppConstants.PEOCESS_VALUE_KEY) == null ? 0
				: context.getAttribute(AppConstants.PEOCESS_VALUE_KEY));
		int offset = (Integer) (context
				.getAttribute(AppConstants.INSTALL_OFFSET_KEY) == null ? 0
				: context.getAttribute(AppConstants.INSTALL_OFFSET_KEY));
		int weight = (Integer) (context.getAttribute(AppConstants.WEIGHT_KEY) == null ? 1
				: context.getAttribute(AppConstants.WEIGHT_KEY));
		return value / weight + offset;
	}
}

/*
 * 修改历史 $Log$
 */